<?php
namespace app\admin\controller;
use app\common\BaseController;
use app\admin\model\CateGory as CateGoryModel;
use think\Db;
class CateGory extends BaseController
{
	public function index(){
		return view('index');
	}
	public function del($id){
		if(request()->isAjax() && request()->isGet()){ 
            CateGoryModel::destroy($id);
            return 'success';
        }
	}
	public function edit(CateGoryModel $CateGory,$id){
		
		if(request()->isAjax() && request()->isPost()){
			return $CateGory->updateCate();
		}
		$cate = CateGoryModel::where('id',$id)->find();
		$parent_id = Db::name('CateGory')->field('category_name,parent_id,id')->select();

		$parent_id = generateTree($parent_id);

		return view('edit',['cate'=>$cate,'CateGory'=>$parent_id]);
	}

	public function addCateGory(CateGoryModel $CateGory){

		if(request()->isAjax() && request()->isPost()){
			return $CateGory->add();

		}
		$parent_id = Db::name('CateGory')->field('category_name,parent_id,id')->select();

		$parent_id = generateTree($parent_id);

		return view('add',['CateGory'=>$parent_id]);
	}
	public function getInfo(CateGoryModel $CateGory){
		$page = input('page');
    	$limit = input('limit');
    	$CateGory = $CateGory->Aselect($page,$limit);
    	return $CateGory;
	}
}